package com.scbo.activity;

import com.scbo.DTO.Buildorder;
import com.scbo.main.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class CreateActivity extends Activity implements OnClickListener {
	Spinner firstRace;
	Spinner secondRace;
	Spinner typeMatch;
	EditText buildName;
	EditText buildNote;
	EditText buildUrlInfo;
	Button btnNext;
	int typeMatchup = 0;
	int typeMode = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_create);
		firstRace = (Spinner) findViewById(R.id.inputFirstRace);
		secondRace = (Spinner) findViewById(R.id.inputSecondRace);
		typeMatch = (Spinner) findViewById(R.id.inputTypeMatch);
		buildName = (EditText) findViewById(R.id.etInputNameBO);
		buildNote = (EditText) findViewById(R.id.etInputNote);
		buildUrlInfo = (EditText) findViewById(R.id.etInputInfoUrl);
		btnNext = (Button) findViewById(R.id.btnNextCreate);

	}

	public void getValueFromSpinner() {
		String firstRacetxt = String.valueOf(firstRace.getSelectedItem());
		String secondRacetxt = String.valueOf(secondRace.getSelectedItem());
		String typeMatchtxt = String.valueOf(typeMatch.getSelectedItem());

		if (firstRacetxt.equals("Terran")) {
			if (secondRacetxt.equals("Terran")) {
				typeMatchup = MainActivity.TvsT;
			} else if (secondRacetxt.equals("Protoss")) {
				typeMatchup = MainActivity.TvsP;
			} else if (secondRacetxt.equals("Zerg")) {
				typeMatchup = MainActivity.TvsZ;
			}

		} else if (firstRacetxt.equals("Protoss")) {
			if (secondRacetxt.equals("Terran")) {
				typeMatchup = MainActivity.PvsT;
			} else if (secondRacetxt.equals("Protoss")) {
				typeMatchup = MainActivity.PvsP;
			} else if (secondRacetxt.equals("Zerg")) {
				typeMatchup = MainActivity.PvsZ;
			}

		} else if (firstRacetxt.equals("Zerg")) {
			if (secondRacetxt.equals("Terran")) {
				typeMatchup = MainActivity.ZvsT;
			} else if (secondRacetxt.equals("Protoss")) {
				typeMatchup = MainActivity.ZvsP;
			} else if (secondRacetxt.equals("Zerg")) {
				typeMatchup = MainActivity.ZvsZ;
			}
		}

		if (typeMatchtxt.equals("Standard Builds")) {
			typeMode = MainActivity.StandardBuilds;
		} else if (typeMatchtxt.equals("Macro Builds")) {
			typeMode = MainActivity.MarcoBuilds;
		} else if (typeMatchtxt.equals("Aggressive Builds")) {
			typeMode = MainActivity.AggressiveBuilds;
		} else if (typeMatchtxt.equals("All-in Builds")) {
			typeMode = MainActivity.AllInBuilds;
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.create, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		Intent i = null;
		switch (v.getId()) {
		case R.id.btnNextCreate:
			getValueFromSpinner();
			String nameBO = buildName.getText().toString();
			String noteBO = buildNote.getText().toString();
			String urlInfoBO = buildUrlInfo.getText().toString();
			Buildorder buildOrder = new Buildorder(nameBO, noteBO, urlInfoBO,
					typeMatchup, typeMode, urlInfoBO);
			i = new Intent(this, CreateItemActivity.class);
			i.putExtra("buildOrder", buildOrder);
			startActivity(i);
			break;

		default:
			break;
		}
	}

}
